#include "supervisaodialogimpl.h"
#include "loginUi.h"

extern loginUi *login;

//
supervisaoDialogImpl::supervisaoDialogImpl( QWidget * parent, Qt::WFlags f) 
	: QDialog(parent, f)
{
	setupUi(this);
	connect(pushButton,SIGNAL(clicked()),this,SLOT(updateClicked2()));
	for(int i = 0; i < 12; i++) {
		QTableWidgetItem  *tmpItem = new QTableWidgetItem("");
		tmpItem->setFlags(Qt::ItemIsEnabled);
		tmpItem->setTextAlignment(Qt::AlignCenter);
		dataTable->setItem(i,0,tmpItem);;
	}
}

void supervisaoDialogImpl::updateClicked2() {
	QStringList ToSend;
	ToSend.push_back(nameActive);
	ToSend.push_back(QString::number(idSimuladorActive));
	login->win.sendFunction(GET_ALL_DATA_FROM_WELL,ToSend);
	login->win.sendFunction(GET_LETTER_FROM_WELL,ToSend);
}

void supervisaoDialogImpl::setup(const wells &Well) {
	lb_name->setText(Well.name);
	nameActive =  Well.name;
	idSimuladorActive = Well.idSimulador;
	printf("WEELLL NAMMMEEEE %s\n",Well.name.toStdString().c_str());
	lb_others->setText("ID: " + QString::number(Well.id) + " Mestre: " + login->win.sMap[Well.idSimulador].name);
	lb_status->setText(Well.getStringState());
	for(int i = 0; i < 12; i++) {
		if(!dataTable->item(i,0)) {
			QTableWidgetItem  *tmpItem = new QTableWidgetItem(Well.onlineVariable[i]);
			tmpItem->setFlags(Qt::ItemIsEnabled);
			tmpItem->setTextAlignment(Qt::AlignCenter);
			dataTable->setItem(i,0,tmpItem);;
		}else
			dataTable->item(i,0)->setText(Well.onlineVariable[i]);
	}
	this->show();
}

void supervisaoDialogImpl::drawChart(const wells &Well) {
	curve.setRawData(Well.l.x,Well.l.y,200);	
	curve.attach(ch_letter);
	ch_letter->replot();
}
//

